#ifndef V2_NIM_DEF_CALLBACK_H
#define V2_NIM_DEF_CALLBACK_H
#include "v2_nim_def_struct.hpp"
namespace v2 {
/// @brief 通用成功
template <typename T>
class V2NIMSuccessCallback : public nstd::function<void(T)> {
public:
    using nstd::function<void(T)>::function;
    using nstd::function<void(T)>::operator=;
    using nstd::function<void(T)>::operator();
    V2NIMSuccessCallback<T>(nstd::function<void(T)> func)
        : nstd::function<void(T)>(func) {}
};

template <>
class V2NIMSuccessCallback<void> : public nstd::function<void()> {
public:
    using nstd::function<void()>::function;
    using nstd::function<void()>::operator=;
    using nstd::function<void()>::operator();
    V2NIMSuccessCallback<void>(nstd::function<void()> func)
        : nstd::function<void()>(func) {}
};

/// @brief 通用失败
/// @param error 错误信息
using V2NIMFailureCallback = nstd::function<void(V2NIMError error)>;

/// @brief 通用进度
/// @param progress 进度, 0-100
using V2NIMProgressCallback = nstd::function<void(uint32_t progress)>;

/// @brief 获取重连延时
/// @param defaultDelay 默认延时, 单位毫秒
/// @return uint32_t 延时, 单位毫秒
using V2NIMReconnectDelayProvider = nstd::function<uint32_t(uint32_t defaultDelay)>;

/// @struct 登录状态监听
struct V2NIMLoginListener {
    /// 登录状态变更
    nstd::function<void(V2NIMLoginStatus)> onLoginStatus;
    /// 登录失败
    nstd::function<void(V2NIMError)> onLoginFailed;
    /// 被踢下线
    nstd::function<void(V2NIMKickedOfflineDetail)> onKickedOffline;
    /// 登录客户端变更
    nstd::function<void(V2NIMLoginClientChange, nstd::vector<V2NIMLoginClient>)> onLoginClientChanged;
    /// @internal
    bool operator==(const V2NIMLoginListener& other) const {
        return onLoginStatus == other.onLoginStatus && onLoginFailed == other.onLoginFailed && onKickedOffline == other.onKickedOffline &&
               onLoginClientChanged == other.onLoginClientChanged;
    }
};

/// @struct 登录详细信息监听
struct V2NIMLoginDetailListener {
    /// 连接状态变更
    nstd::function<void(V2NIMConnectStatus)> onConnectStatus;
    /// 连接断开
    nstd::function<void(nstd::optional<V2NIMError>)> onDisconnected;
    /// 连接失败
    nstd::function<void(V2NIMError)> onConnectFailed;
    /// 数据同步
    nstd::function<void(V2NIMDataSyncType, V2NIMDataSyncState, nstd::optional<V2NIMError>)> onDataSync;
    /// @internal
    bool operator==(const V2NIMLoginDetailListener& other) const {
        return onConnectStatus == other.onConnectStatus && onDisconnected == other.onDisconnected && onConnectFailed == other.onConnectFailed &&
               onDataSync == other.onDataSync;
    }
};

/// @struct 会话监听
struct V2NIMConversationListener {
    /// 会话同步开始
    nstd::function<void()> onSyncStarted;
    /// 会话同步完成
    nstd::function<void()> onSyncFinished;
    /// 会话同步错误
    nstd::function<void(V2NIMError error)> onSyncFailed;
    /// 会话创建
    nstd::function<void(V2NIMConversation conversation)> onConversationCreated;
    /// 会话删除
    nstd::function<void(nstd::vector<nstd::string> conversationIds)> onConversationDeleted;
    /// 会话更新
    nstd::function<void(nstd::vector<V2NIMConversation> conversationList)> onConversationChanged;
    /// 会话总未读数变更
    nstd::function<void(uint32_t unreadCount)> onTotalUnreadCountChanged;
    /// 根据过滤条件订阅的会话未读数变更
    nstd::function<void(V2NIMConversationFilter filter, uint32_t unreadCount)> onUnreadCountChangedByFilter;
    /// 同账号多端标记会话 ACK 通知时间戳变更
    nstd::function<void(const nstd::string& conversationId, time_t readTime)> onConversationReadTimeUpdated;
};

/// @struct 会话分组监听
struct V2NIMConversationGroupListener {
    /// 会话分组创建
    nstd::function<void(V2NIMConversationGroup conversationGroup)> onConversationGroupCreated;
    /// 会话分组删除
    nstd::function<void(nstd::string groupId)> onConversationGroupDeleted;
    /// 会话分组更新
    nstd::function<void(V2NIMConversationGroup conversationGroup)> onConversationGroupChanged;
    /// 会话加入会话分组
    nstd::function<void(nstd::string groupId, nstd::vector<V2NIMConversation> conversationList)> onConversationsAddedToGroup;
    /// 会话移出会话分组
    nstd::function<void(nstd::string groupId, nstd::vector<nstd::string> conversationIds)> onConversationsRemovedFromGroup;
};

/// @struct 消息监听
struct V2NIMMessageListener {
    /// 收到一条新消息
    nstd::function<void(nstd::vector<V2NIMMessage> messages)> onReceiveMessages;
    /// 点对点已读回执
    nstd::function<void(nstd::vector<V2NIMP2PMessageReadReceipt> readReceipts)> onReceiveP2PMessageReadReceipts;
    /// 群已读回执
    nstd::function<void(nstd::vector<V2NIMTeamMessageReadReceipt> readReceipts)> onReceiveTeamMessageReadReceipts;
    /// 消息撤回
    nstd::function<void(nstd::vector<V2NIMMessageRevokeNotification> revokeNotifications)> onMessageRevokeNotifications;
    /// 消息 pin 状态
    nstd::function<void(V2NIMMessagePinNotification pinNotification)> onMessagePinNotification;
    /// 消息快捷评论
    nstd::function<void(V2NIMMessageQuickCommentNotification quickCommentNotification)> onMessageQuickCommentNotification;
    /// 消息被删除
    nstd::function<void(nstd::vector<V2NIMMessageDeletedNotification> messageDeletedNotification)> onMessageDeletedNotifications;
    /// 清空会话历史消息
    nstd::function<void(nstd::vector<V2NIMClearHistoryNotification> clearHistoryNotification)> onClearHistoryNotifications;
    /// 本端发送消息状态回调
    nstd::function<void(const V2NIMMessage& message)> onSendMessage;
};

/// @struct 通知监听
struct V2NIMNotificationListener {
    /// 收到自定义
    nstd::function<void(nstd::vector<V2NIMCustomNotification> customNotification)> onReceiveCustomNotifications;
    /// 收到广播
    nstd::function<void(nstd::vector<V2NIMBroadcastNotification> broadcastNotification)> onReceiveBroadcastNotifications;
};

/// @struct 群组监听
struct V2NIMTeamListener {
    /// 群组信息同步开始
    nstd::function<void()> onSyncStarted;
    /// 群组信息同步完成
    nstd::function<void()> onSyncFinished;
    /// 群组信息同步失败
    nstd::function<void(V2NIMError error)> onSyncFailed;
    /// 群组创建
    nstd::function<void(V2NIMTeam team)> onTeamCreated;
    /// 群组解散
    nstd::function<void(nstd::vector<V2NIMTeam> teams)> onTeamDismissed;
    /// 加入群组
    nstd::function<void(V2NIMTeam team)> onTeamJoined;
    /// 离开群组
    nstd::function<void(V2NIMTeam team, bool isKicked)> onTeamLeft;
    /// 群组信息更新
    nstd::function<void(V2NIMTeam team)> onTeamInfoUpdated;
    /// 群组成员加入
    nstd::function<void(nstd::vector<V2NIMTeamMember> teamMembers)> onTeamMemberJoined;
    /// 群组成员被踢
    nstd::function<void(nstd::string operateAccountId, nstd::vector<V2NIMTeamMember> teamMembers)> onTeamMemberKicked;
    /// 群组成员退出群组
    nstd::function<void(nstd::vector<V2NIMTeamMember> teamMembers)> onTeamMemberLeft;
    /// 群组成员信息变更
    nstd::function<void(nstd::vector<V2NIMTeamMember> teamMembers)> onTeamMemberInfoUpdated;
    /// 收到入群信息
    nstd::function<void(V2NIMTeamJoinActionInfo joinActionInfo)> onReceiveTeamJoinActionInfo;
};

/// @struct 设置监听
struct V2NIMSettingListener {
    /// 群组消息免打扰
    nstd::function<void(nstd::string teamId, V2NIMTeamType teamType, V2NIMTeamMessageMuteMode muteMode)> onTeamMessageMuteModeChanged;
    /// 点对点消息免打扰
    nstd::function<void(nstd::string accountId, V2NIMP2PMessageMuteMode muteMode)> onP2PMessageMuteModeChanged;
};

/// @struct 用户资料监听
struct V2NIMUserListener {
    /// 用户资料变更
    nstd::function<void(nstd::vector<V2NIMUser> users)> onUserProfileChanged;
    /// 添加黑名单
    nstd::function<void(V2NIMUser user)> onBlockListAdded;
    /// 移除黑名单
    nstd::function<void(nstd::string accountId)> onBlockListRemoved;
};

/// @struct 好友监听
struct V2NIMFriendListener {
    /// 添加好友
    nstd::function<void(V2NIMFriend friendInfo)> onFriendAdded;
    /// 删除好友
    nstd::function<void(nstd::string accountId, V2NIMFriendDeletionType deletionType)> onFriendDeleted;
    /// 添加好友申请
    nstd::function<void(V2NIMFriendAddApplication applicationInfo)> onFriendAddApplication;
    /// 添加好友申请被拒绝
    nstd::function<void(V2NIMFriendAddApplication rejectionInfo)> onFriendAddRejected;
    /// 更新好友信息
    nstd::function<void(V2NIMFriend friendInfo)> onFriendInfoChanged;
};

/// @struct 聊天室实例监听
struct V2NIMChatroomClientListener {
    /// 聊天室状态
    nstd::function<void(V2NIMChatroomStatus status, nstd::optional<V2NIMError> error)> onChatroomStatus;
    /// 进入聊天室
    nstd::function<void()> onChatroomEntered;
    /// 退出聊天室
    nstd::function<void(nstd::optional<V2NIMError> error)> onChatroomExited;
    /// 自己被踢出聊天室
    nstd::function<void(V2NIMChatroomKickedInfo kickedInfo)> onChatroomKicked;
};

/// @struct 聊天室业务监听
struct V2NIMChatroomListener {
    /// 收到新消息
    nstd::function<void(nstd::vector<V2NIMChatroomMessage> messages)> onReceiveMessages;
    /// 聊天室成员进入
    nstd::function<void(V2NIMChatroomMember member)> onChatroomMemberEnter;
    /// 聊天室成员退出
    nstd::function<void(nstd::string accountId)> onChatroomMemberExit;
    /// 成员角色更新
    nstd::function<void(V2NIMChatroomMemberRole previousRole, V2NIMChatroomMember member)> onChatroomMemberRoleUpdated;
    /// 成员信息更新
    nstd::function<void(V2NIMChatroomMember member)> onChatroomMemberInfoUpdated;
    /// 自己的禁言状态变更
    nstd::function<void(bool chatBanned)> onSelfChatBannedUpdated;
    /// 自己的临时禁言状态变更
    nstd::function<void(bool tempChatBanned, uint64_t tempChatBannedDuration)> onSelfTempChatBannedUpdated;
    /// 聊天室信息更新
    nstd::function<void(V2NIMChatroomInfo chatroomInfo)> onChatroomInfoUpdated;
    /// 聊天室禁言状态更新
    nstd::function<void(bool chatBanned)> onChatroomChatBannedUpdated;
    /// 消息撤回回调
    nstd::function<void(nstd::string messageClientId, uint64_t messageTime)> onMessageRevokedNotification;
    /// 更新角色标签
    nstd::function<void(nstd::vector<nstd::string> tags)> onChatroomTagsUpdated;
    /// 本端发送消息状态回调
    nstd::function<void(const V2NIMChatroomMessage& message)> onSendMessage;
};

/// @struct AI 相关服务消息监听
struct V2NIMAIListener {
    /// AI 消息的响应的回调
    nstd::function<void(V2NIMAIModelCallResult response)> onProxyAIModelCall;
};

/// @struct 信令监听回调
struct V2NIMSignallingListener {
    /// 在线事件回调
    nstd::function<void(const V2NIMSignallingEvent& event)> onOnlineEvent;
    /// 离线事件回调
    nstd::function<void(const nstd::vector<V2NIMSignallingEvent>& events)> onOfflineEvent;
    /// 多端事件操作同步回调
    nstd::function<void(const V2NIMSignallingEvent& event)> onMultiClientEvent;
    /// 登录后，同步还在的信令频道房间列表
    nstd::function<void(const nstd::vector<V2NIMSignallingRoomInfo>& roomInfoList)> onSyncRoomInfoList;
};

}  // namespace v2

#endif
